package com.matt.domain.observation;

import com.matt.commons.model.Domain;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Map;
import java.util.Objects;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/8/11
 * *******************************
 */
@Entity
@Table(name = "observation_new")
@Data
@EqualsAndHashCode(callSuper = true)
public class ObservationNew extends Domain{

    @Column(columnDefinition = "varchar(32) COMMENT '对应安排课程id'")
    private String coursePlanId;

    @Column(columnDefinition = "varchar(255) COMMENT '所属分类'")
    private String typeName;

    @Column(columnDefinition = "int default 0 COMMENT '分类码'")
    private Integer typeCode=0;

    @Column(columnDefinition = "varchar(255) COMMENT '能力'")
    private String ability;

    @Column(columnDefinition = "varchar(32) COMMENT '问题描述'")
    private String question;

    @Column(columnDefinition = "int default 0 COMMENT '课题类型：1托班，2早教'")
    private Integer category=0;

    @Column(columnDefinition = "int default 0 COMMENT '课程类型：1SAT早教，2园区自建，3公共课程'")
    private Integer courseType=0;

    @Column(columnDefinition = "int default 0 COMMENT '序号'")
    private Integer orderIndex=0;

    @Column(columnDefinition = "varchar(32) COMMENT '对应课程id'")
    private String courseId;
    @Column(columnDefinition = "int default 1 COMMENT '是否多选'")
    private Integer multiSelect;

    public static ObservationNew of(Map observationMap, String coursePlanId, Integer category, Integer courseType, Integer orderIndex){
        ObservationNew observation = new ObservationNew();
        observation.setTypeName(observationMap.get("typeName").toString());
        if(observationMap.get("typeCode").toString()==""){
            observation.setTypeCode(10000);
        }else{
            observation.setTypeCode(Integer.valueOf(observationMap.get("typeCode").toString()));
        }
        if(Objects.isNull(observationMap.get("multiSelect"))||observationMap.get("multiSelect").toString()==""){
            observation.setMultiSelect(1);
        }else{
            observation.setMultiSelect(Integer.parseInt(observationMap.get("multiSelect").toString()));
        }
       // observation.setMultiSelect(Integer.parseInt(observationMap.get("multiSelect").toString()));
        observation.setQuestion(observationMap.get("question").toString());
        observation.setCoursePlanId(coursePlanId);
        observation.setCategory(category);
        observation.setCourseType(courseType);
        observation.setOrderIndex(orderIndex);
        return observation;
    }
}
